#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

int dx[4] = { 0 , 0 , -1 , 1 };
int dy[4] = { -1, 1 , 0 , 0 };
int _prev;
int m, n;

void dfs(vector<vector<int>>& image, int i, int j, int color)
{
    image[i][j] = color;

    for (int k = 0; k < 4; ++k)
    {
        int x = i + dx[k];
        int y = j + dy[k];

        if (x >= 0 && x < m && y >= 0 && y < n && image[x][y] == _prev)
        {
            dfs(image, x, y, color);
        }
    }
}

vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
    if (image[sr][sc] == color) return image;

    m = image.size();
    n = image[0].size();
    _prev = image[sr][sc];

    dfs(image, sr, sc, color);

    return image;
}

int main()
{
    vector<vector<int>> image;

    image.push_back({ 1,1,1 });
    image.push_back({ 1,1,0 });
    image.push_back({ 1,0,1 });

    floodFill(image, 1, 1, 2);

	return 0;
}